package cn.com.shopec.erp.stock.excel.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import cn.com.shopec.erp.common.excel.ExcelBaseExport;

public class ProductPackageExcelExport extends ExcelBaseExport {

	public ProductPackageExcelExport(List<Map<String, Object>> data, String fileName,
			HttpServletResponse response) {
		super(data, fileName, response);
	}

	@SuppressWarnings("unchecked")
	@Override
	protected Row setColumnMapping(Object data, Row row) {
		Map<String, Object> model = (Map<String, Object>)data;
		int cellIndex = 0;
		Cell cell = row.createCell(cellIndex++);
		cell.setCellValue(model.get("prodPackageNo")==null?"":model.get("prodPackageNo").toString());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(model.get("channelOrderId")==null?"":model.get("channelOrderId").toString());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(getChannelOrderName(model.get("channelOrderType")==null?"":model.get("channelOrderType").toString()));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(model.get("whName")==null?"":model.get("whName").toString());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(getStateName(model.get("state")==null?0:Integer.parseInt(model.get("state").toString())));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(getOrderType(model.get("channelOrderType")==null?"":model.get("channelOrderType").toString()));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(model.get("deliveryTime")==null?null:model.get("deliveryTime").toString().substring(0, 19));
		
		return row;
	}

	@Override
	protected List<String> setExcelTitleValue() {
		List<String> title = new ArrayList<String>();
		title.add("包裹编号");
		title.add("订单编号");
		title.add("订单渠道");
		title.add("仓库");
		title.add("出库状态");
		title.add("订单类型");
		title.add("发货时间");
		return title;
	}
	
	private String getChannelOrderName(String type){
		if(type.equals("0")){
			return "京东";
		}
	    if(type.equals("1")){
			return "淘宝";
		}
	    if(type.equals("2")){
			return "天猫";
		}
		return null;
	}
	
	private String getStateName(int state){
		String result = "";
		switch(state){
			case 0 : result="未出库";break;
			case 1 : result="已生成出库单";break;
			case 2 : result="已出库";break;
			default : break;
		}
		return result;
	}
	
	private String getOrderType(String type){
		if(type.equals("0")){
			return "白拿";
		}
	    if(type.equals("1")){
			return "返还";
		}
	    if(type.equals("2")){
			return "天猫";
		}
		return null;
	}

}
